package com.example.readFile;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.InputStreamReader;
import java.io.UnsupportedEncodingException;

public class Test {

	public static void main(String[] args) throws UnsupportedEncodingException {
		String path = Test.class.getResource("").getPath() + "/zfhmhhzb.65002.0000.dat";
		readTxtFile(path, "GBK");
	}

	public static void readTxtFile(String filePath, String charset) {
		try {
			String encoding = charset;
			File file = new File(filePath);
			if (file.isFile() && file.exists()) {
				InputStreamReader read = new InputStreamReader(new FileInputStream(file), encoding);// 考虑到编码格式
				BufferedReader bufferedReader = new BufferedReader(read);
				String lineTxt = null;
				while ((lineTxt = bufferedReader.readLine()) != null) {
					String[] lineTxts = lineTxt.split("\\|", -1);
					String sql = "insert into PUB_PMSBANKNO "
							+ "(pbn_bankno, pbn_banktype, pbn_citycode, pbn_bankname, pbn_stt, pbn_address, pbn_banknotype,"
							+ " pbn_joiner, pbn_nodecode, pbn_postcode, pbn_effectivedate, pbn_expirydate, pbn_updatedate, "
							+ "pbn_opertype, pbn_phone, pbn_clearbankno)\r\n" + "values ('" + lineTxts[0] + "', '"
							+ lineTxts[1] + "', '" + lineTxts[9] + "', '" + lineTxts[10] + "', '1', "
							+ "null, null, null, null, null, null, null, null, null, null, null);"
							+ System.getProperty("line.separator");
					WriteFile.writeSql("d:/temp/pmsbank.sql", sql, "GBK");
				}
				read.close();
			} else {
				System.out.println("找不到指定的文件");
			}
		} catch (Exception e) {
			System.out.println("读取文件内容出错");
			e.printStackTrace();
		}
	}
}
